<%@ page language="java" contentType="text/html" pageEncoding="utf-8"%>
<%@include file="/WEB-INF/pages/common/common.jsp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head> 
    <%@include file="/WEB-INF/pages/common/head.jsp"%>
    <title><spring:message code="title.ipic.target"/></title>
      <style type="text/css">
        .font_stress{
            color: red;font-size: 13px;font-weight:bold;
        }
    </style>
    <script type="text/javascript">
           var operateDialog;
          var datagrid;
           var lastIndex;
	        $(function() {
	            datagrid=$('#datagrid').datagrid({
	                onClickRow:function(rowIndex){
						datagrid.datagrid('selectRow', rowIndex);
						if (lastIndex != rowIndex){
								datagrid.datagrid('endEdit', lastIndex);
								datagrid.datagrid('beginEdit', rowIndex);
						}else{
							datagrid.datagrid('beginEdit', rowIndex);
						}
						lastIndex = rowIndex;
						setEditing(rowIndex);
					}
	            });
	        });
	        
	       function save_(){
	       
	      
            imonJYRH.showZone();
            var rows = datagrid.datagrid('getRows');
            
            for ( var i = 0; i < rows.length; i++) {
		        datagrid.datagrid('endEdit', i);
		   	 }
            var effectData = new Object();
            effectData["specialClaimDetail"] = JSON.stringify(rows);
            effectData["specialClaim"] =  JSON.stringify(imonJYRH.serializeObject($("#tableForm *")));
            
            $.ajax({
                url : '${path}/business/supplier_quality/special_claim/ ajaxModify.do',
                 data : effectData,
                 cache : false,
                 async : true,
                 dataType : "json",
                success : function(reMsg) {
                    if(reMsg.success){
                        parent.returnResult();
                        message.show({ msg : reMsg.msg,title : '<spring:message code='msg.tip'/>',showType:'slide'});
                    }else{
                        if(!imonJYRH.isBlank(reMsg.obj)){
                            $.messager.alert('<spring:message code='msg.tip'/>',reMsg['obj']);
                        }else{
                            $.messager.alert('<spring:message code='msg.tip'/>',reMsg['msg']);
                        }
                    }
                    imonJYRH.hideZone();
                }
            });
        }
   function dialogSupplier_(){
            var href = '${path}/basedata/supplier/dialogUI.do';
            operateDialog = $("#operateDialog").dialog({
                title : '<spring:message code='msg.dialog.choose'/>',
                width : 650,
                height : 400
            });
            $("#operateIFrame")[0].src=href;
            operateDialog.dialog('open');
        }
     function dialogSupplierReturn(row){
            $("#supplierId").val(row['id']);
            $("#supplierCode").val(row['code']);
            $("#supplierName").val(row['name']);
            operateDialog.dialog('close');
        }
      function setEditing(rowIndex){
		var rows = datagrid.datagrid('getRows');
	    var editors = datagrid.datagrid('getEditors', rowIndex);
	    
	    var incident1 = rows[rowIndex]['incident1']; 
	    var incident2 = rows[rowIndex]['incident2']; 
	    var incident3 = rows[rowIndex]['incident3']; 
	    var incident4 = rows[rowIndex]['incident4']; 
	    
	    var i1 = editors[0];   
	    var i2 = editors[1];
	    var i3 = editors[2];
	    var i4 = editors[3];
	    var value1=0;
	    var value2=0;
	    var value3=0;
	    var value4=0;
	    
	    i1.target.bind('change', function(){
	       value1=i1.target.val(); 
	      var total=0;
	      
	      if(!imonJYRH.isBlank(i1.target.val())){
	        total=total+i1.target.val()*(-2);
	       }
	       
	       if(value2!=0){
	            total=total+value2*(-5);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident2)){
			        total=total+rows[rowIndex].incident2*(-5);
			    }
	       } 
	       
	      
	       if(value3!=0){
	            total=total+value3*(-7);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident3)){
			        total=total+rows[rowIndex].incident3*(-7);
			    }
	       } 
	       
	        if(value4!=0){
	            total=total+value4*(-10);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident4)){
			        total=total+rows[rowIndex].incident4*(-10);
			    }
	       } 
	       
	        rows[rowIndex].value=total;
	    });   
	    i2.target.bind('change', function(){
	   		value2=i2.target.val();
	         var total=0;
			      
		   if(!imonJYRH.isBlank(i2.target.val())){
	          total=total+i2.target.val()*(-5);
	       }
	       
	       if(value1!=0){
	            total=total+value1*(-2);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident1)){
			        total=total+rows[rowIndex].incident1*(-2);
			    }
	       } 
	       
	      
	       if(value3!=0){
	            total=total+value3*(-7);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident3)){
			        total=total+rows[rowIndex].incident3*(-7);
			    }
	       } 
	       
	        if(value4!=0){
	            total=total+value4*(-10);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident4)){
			        total=total+rows[rowIndex].incident4*(-10);
			    }
	       } 
		     
		     
		     rows[rowIndex].value=total;
	    });
		    i3.target.bind('change', function(){   
		    value3=i3.target.val();
	         var total=0;
			    
		   if(!imonJYRH.isBlank(i3.target.val())){
	          total=total+i3.target.val()*(-7);
	       }
	       
	       if(value1!=0){
	            total=total+value1*(-2);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident1)){
			        total=total+rows[rowIndex].incident1*(-2);
			    }
	       } 
	       
	      
	       if(value2!=0){
	            total=total+value2*(-5);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident2)){
			        total=total+rows[rowIndex].incident2*(-5);
			    }
	       } 
	       
	        if(value4!=0){
	            total=total+value4*(-10);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident4)){
			        total=total+rows[rowIndex].incident4*(-10);
			    }
	       }    
			    
			    
		    rows[rowIndex].value=total;
	    });
	    i4.target.bind('change', function(){
	       value4=i4.target.val();
	        var total=0;
			
			if(!imonJYRH.isBlank(i4.target.val())){
	          total=total+i4.target.val()*(-10);
	       }
	       
	       if(value1!=0){
	            total=total+value1*(-2);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident1)){
			        total=total+rows[rowIndex].incident1*(-2);
			    }
	       } 
	       
	      
	       if(value2!=0){
	            total=total+value2*(-5);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident2)){
			        total=total+rows[rowIndex].incident2*(-5);
			    }
	       } 
	       
	        if(value3!=0){
	            total=total+value3*(-7);
	       }else{
	            if(!imonJYRH.isBlank(rows[rowIndex].incident3)){
			        total=total+rows[rowIndex].incident3*(-7);
			    }
	       }  
			     
		    rows[rowIndex].value=total;
	    });
	}
    </script>
</head>
<body class="easyui-layout">
   <div data-options="region:'center'">
    <div class="datagrid-toolbar" style="height:410px">
        <table width="100%"  class="tableForm" id="tableForm">
            <tr>
          			  <input type="hidden"   value="${specialClaimVo.id}" name="id"/>
          			  <input type="hidden"   value="${specialClaimVo.year}" name="year"/>
                <td>
                    供应商：<input id="supplier" type="text"   disabled value="${specialClaimVo.code}" name="code"/>
                </td>
                <td>
                    SupplierName供应商名称：<input type="text" disabled  value="${specialClaimVo.name}"  name="name"/>
                </td>
                <td>
                   年：<input type="text" disabled value="${specialClaimVo.year}"  name="year"/>
                </td>
            </tr>
        </table>
        <hr width="650px"/>
        <table width="100%" id="datagrid" singleSelect="true" class="tableForm">
            <thead>
            <tr>
            	<th field="month" width="60" hidden="true">月份</th>
                <th field="month1" width="60">月份</th>
                <th field="incident1" width="60" data-options="editor:{type:'numberbox',options:{precision:0}}">i1</th>
                <th field="incident2" width="60" data-options="editor:{type:'numberbox',options:{precision:0}}">i2</th>
                <th field="incident3" width="60" data-options="editor:{type:'numberbox',options:{precision:0}}">i3</th>
                <th field="incident4" width="60" data-options="editor:{type:'numberbox',options:{precision:0}}">i4</th>
                <th field="value" width="100">得分</th>
                <th field="comment" width="250" data-options="editor:{type:'text'}">评论</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td field="month" width="60" hidden="true">01</td>
                <td>一月</td>
                <td field="spe1i1">${specialClaimVo.spe1i1}</td>
                <td field="spe1i2">${specialClaimVo.spe1i2}</td>
                <td field="spe1i3">${specialClaimVo.spe1i3}</td>
                <td field="spe1i4">${specialClaimVo.spe1i4}</td>
                <td field="value1">${specialClaimVo.value1}</td>
                <td field="comment1">${specialClaimVo.comment1}</td>
            </tr>
            <tr>
            	<td field="month" width="60" hidden="true">02</td>
                <td>二月</td>
                <td field="spe2i1">${specialClaimVo.spe2i1}</td>
                <td field="spe2i2">${specialClaimVo.spe2i2}</td>
                <td field="spe2i3">${specialClaimVo.spe2i3}</td>
                <td field="spe2i4">${specialClaimVo.spe2i4}</td>
                <td field="value2">${specialClaimVo.value2}</td>
                <td field="comment2">${specialClaimVo.comment2}</td>
            </tr>
            <tr>
                <td field="month" width="60" hidden="true">03</td>
                <td>三月</td>
                <td field="spe3i1">${specialClaimVo.spe3i1}</td>
                <td field="spe3i2">${specialClaimVo.spe3i2}</td>
                <td field="spe3i3">${specialClaimVo.spe3i3}</td>
                <td field="spe3i4">${specialClaimVo.spe3i4}</td>
                <td field="value3">${specialClaimVo.value3}</td>
                <td field="comment3">${specialClaimVo.comment3}</td>
            </tr>
            <tr>
               <td field="month" width="60" hidden="true">04</td>
                <td>四月</td>
                <td field="spe4i1">${specialClaimVo.spe4i1}</td>
                <td field="spe4i2">${specialClaimVo.spe4i2}</td>
                <td field="spe4i3">${specialClaimVo.spe4i3}</td>
                <td field="spe4i4">${specialClaimVo.spe4i4}</td>
                <td field="value4">${specialClaimVo.value4}</td>
                <td field="comment4">${specialClaimVo.comment4}</td>
            </tr>
            <tr>
                 <td field="month" width="60" hidden="true">05</td>
                <td>五月</td>
                <td field="spe5i1">${specialClaimVo.spe5i1}</td>
                <td field="spe5i2">${specialClaimVo.spe5i2}</td>
                <td field="spe5i3">${specialClaimVo.spe5i3}</td>
                <td field="spe5i4">${specialClaimVo.spe5i4}</td>
                <td field="value5">${specialClaimVo.value5}</td>
                <td field="comment5">${specialClaimVo.comment5}</td>
            </tr>
            <tr>
               <td field="month" width="60" hidden="true">06</td>
                <td>六月</td>
               <td field="spe6i1">${specialClaimVo.spe6i1}</td>
                <td field="spe6i2">${specialClaimVo.spe6i2}</td>
                <td field="spe6i3">${specialClaimVo.spe6i3}</td>
                <td field="spe6i4">${specialClaimVo.spe6i4}</td>
                <td field="value6">${specialClaimVo.value6}</td>
                <td field="comment6">${specialClaimVo.comment6}</td>
            </tr>
            <tr>
                <td field="month" width="60" hidden="true">07</td>
                <td>七月</td>
                <td field="spe7i1">${specialClaimVo.spe7i1}</td>
                <td field="spe7i2">${specialClaimVo.spe7i2}</td>
                <td field="spe7i3">${specialClaimVo.spe7i3}</td>
                <td field="spe7i4">${specialClaimVo.spe7i4}</td>
                <td field="value7">${specialClaimVo.value7}</td>
                <td field="comment7">${specialClaimVo.comment7}</td>
            </tr>
            <tr>
               <td field="month" width="60" hidden="true">08</td>
                <td>八月</td>
               <td field="spe1i1">${specialClaimVo.spe8i1}</td>
                <td field="spe1i2">${specialClaimVo.spe8i2}</td>
                <td field="spe1i3">${specialClaimVo.spe8i3}</td>
                <td field="spe1i4">${specialClaimVo.spe8i4}</td>
                <td field="value8">${specialClaimVo.value8}</td>
                <td field="comment8">${specialClaimVo.comment8}</td>
            </tr>
             <tr>
               <td field="month" width="60" hidden="true">09</td>
               <td>九月</td>
               <td field="spe9i1">${specialClaimVo.spe9i1}</td>
                <td field="spe9i2">${specialClaimVo.spe9i2}</td>
                <td field="spe9i3">${specialClaimVo.spe9i3}</td>
                <td field="spe9i4">${specialClaimVo.spe9i4}</td>
                <td field="value9">${specialClaimVo.value9}</td>
                <td field="comment9">${specialClaimVo.comment9}</td>
            </tr>
            <tr>
                <td field="month" width="60" hidden="true">10</td>
                <td>十月</td>
               <td field="spe10i1">${specialClaimVo.spe10i1}</td>
                <td field="spe10i2">${specialClaimVo.spe10i2}</td>
                <td field="spe10i3">${specialClaimVo.spe10i3}</td>
                <td field="spe10i4">${specialClaimVo.spe10i4}</td>
                <td field="value10">${specialClaimVo.value10}</td>
                <td field="comment10">${specialClaimVo.comment10}</td>
            </tr>
            <tr>
               <td field="month" width="60" hidden="true">11</td>
                <td>十一月</td>
                <td field="spe11i1">${specialClaimVo.spe11i1}</td>
                <td field="spe11i2">${specialClaimVo.spe11i2}</td>
                <td field="spe11i3">${specialClaimVo.spe11i3}</td>
                <td field="spe11i4">${specialClaimVo.spe11i4}</td>
                <td field="value11">${specialClaimVo.value11}</td>
                <td field="comment11">${specialClaimVo.comment11}</td>
            </tr>
            <tr>
           		<td field="month" width="60" hidden="true">12</td>
                <td>十二月</td>
                <td field="spe12i1">${specialClaimVo.spe12i1}</td>
                <td field="spe12i2">${specialClaimVo.spe12i2}</td>
                <td field="spe12i3">${specialClaimVo.spe12i3}</td>
                <td field="spe12i4">${specialClaimVo.spe12i4}</td>
                <td field="value12">${specialClaimVo.value12}</td>
                <td field="comment12">${specialClaimVo.comment12}</td>
            </tr>
            </tbody>
        </table>
        <br />
        <div align="right">
            <a class="easyui-linkbutton" href="javascript:void(0);" iconCls="icon-save" onclick="save_();"><spring:message code='button.save'/></a>
            <a class="easyui-linkbutton" href="javascript:void(0);" iconCls="icon-no" onclick="parent.operateDialog.dialog('close');"><spring:message code='button.close'/></a>
        </div>
    </div>
</div>
<div id="operateDialog" class="easyui-dialog"
     data-options="iconCls:'icon-save',resizable:true,modal:true,closed: true,collapsible:true,maximizable:true">
    <iframe scrolling="auto" id='operateIFrame' frameborder="0"  src="" style="width:100%;height:100%;"/>
</div>
</body>
</html>